package com.ptmall.app.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.bean.model.db.Account;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.view.TitleBarView;

public class WalletActivity extends BaseMvpActivity {

    TitleBarView titlebar;

    Intent intent;

    TextView walletnum;

    Button recharge;

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_wallet);
    }

    @Override
    public void initViews() {
        titlebar = (TitleBarView) findViewById(R.id.titlebar);
        recharge = (Button) findViewById(R.id.recharge);
        walletnum = (TextView) findViewById(R.id.walletnum);
        titlebar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {
                intent = new Intent(getContext(),WalletListActivity.class);
                startActivity(intent);
            }
        });

        recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intent = new Intent(getContext(),RechargeWalletActivity.class);
                startActivity(intent);
            }
        });

    }

    @Override
    public void initEvents() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        getWalletNum();
    }

    private void getWalletNum(){
        apiDataRepository.getUserInfo(null, new ApiNetResponse<Account>() {
            @Override
            public void onSuccess(Account data) {
                walletnum.setText("￥"+data.wallet);
            }
        });
    }
}
